package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.DegreeBean;
import com.lc.pianostudent.bean.PianoBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.DEGREE_INDEX)
public class PostDegreeIndex extends BaseAsyPost {

    public String user_id;
    public PostDegreeIndex(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostDegreeIndexInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostDegreeIndexInfo info = new PostDegreeIndexInfo();

            info.code = object.optString("code");
            info.degree = object.optString("degree");
            info.xuewei = object.optString("xuewei");
            info.need = object.optString("need");
            info.next = object.optString("next");
            info.start = object.optString("start");
            info.end = object.optString("end");

            JSONArray array = object.optJSONArray("list");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    DegreeBean degreeBean = new DegreeBean();

                    degreeBean.setTitle(o.optString("title"));
                    degreeBean.setNumber(o.optString("number"));
                    degreeBean.setHead(o.optString("head"));



                    info.list.add(degreeBean);
                }

            }


            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostDegreeIndexInfo {

        public String code,degree,xuewei,need,next,start,end;

        public List<DegreeBean> list = new ArrayList<>();
    }

}
